From d592085dc0fec023dd9f3437d4c756d402ed8c8f Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Mon, 18 Dec 2023 11:56:59 +0100 Subject: fix(pages): use dynamic imports for the table of contents The ToCWidget relies on Javascript to display the headings. If JS is disabled in the browser, the widget is empty. For a better UX, we should use dynamic imports. Now, the ToC is only displayed when JS is enabled. --- src/pages/sujet/[slug].tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/pages/sujet/[slug].tsx') diff --git a/src/pages/sujet/[slug].tsx b/src/pages/sujet/[slug].tsx index af78185..8f46677 100644 --- a/src/pages/sujet/[slug].tsx +++ b/src/pages/sujet/[slug].tsx @@ -1,6 +1,7 @@ /* eslint-disable max-statements */ import type { ParsedUrlQuery } from 'querystring'; import type { GetStaticPaths, GetStaticProps } from 'next'; +import dynamic from 'next/dynamic'; import Head from 'next/head'; import NextImage from 'next/image'; import { useRouter } from 'next/router'; @@ -15,7 +16,6 @@ import { PageSidebar, PageBody, LoadingPage, - TocWidget, Spinner, } from '../../components'; import { @@ -49,6 +49,13 @@ import { useTopicsList, } from '../../utils/hooks'; +const Toc = dynamic( + async () => import('../../components').then((mod) => mod.TocWidget), + { + ssr: false, + } +); + export type TopicPageProps = { data: { currentTopic: WPTopic; @@ -169,7 +176,7 @@ const TopicPage: NextPageWithLayout = ({ data }) => { }} /> - {messages.widgets.tocTitle}} tree={[ ...tree, -- cgit v1.2.3